﻿using DevExpress.ExpressApp.Blazor.Components.Models;

namespace EasyXaf.DynamicForm.Blazor.Components;

public class CheckBoxComponent : FieldComponent
{
    protected override object ConvertValue(object value)
    {
        if (bool.TryParse(value?.ToString(), out var boolean))
        {
            return boolean;
        }

        if (Field.Required == true)
        {
            return default(bool);
        }

        return null;
    }

    protected override ComponentModelBase CreateComponentModel()
    {
        return new DxCheckBoxModel<bool>
        {
            Id = Field.Id,
        };
    }
}
